package com.anxin.act.model.editor.controller;

import com.anxin.act.model.editor.service.EditorService;
import com.anxin.framework.security.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


@RestController
@RequestMapping("/wf")
public class EditorController {

    @Autowired
    EditorService editorService;


    @GetMapping("/editor/stencilset")
    public Object getStencilset() throws IOException {
        return editorService.getStencilset();
    }


    @GetMapping(value = "/model/{modelId}/json")
    public Object getEditorJson(@PathVariable(value = "modelId") String modelId, HttpServletRequest request) throws IOException {
//        LoginUser loginUser = tokenService.getLoginUserByCookie(request);
//        if (loginUser == null){
//            return "无权限";
//        }

        return editorService.getEditorJson(modelId);
    }


    @PutMapping("/model/{modelId}/save")
    public void saveModel(@PathVariable(value = "modelId") String modelId, String name, String description,String json_xml, String svg_xml) throws IOException {
        editorService.saveModel(modelId, name, description, json_xml, svg_xml);
    }
}
